﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StockPoint.Admin.General.Board
{
    public partial class EventList : BasePage
    {
        
            /// <summary>
            /// 페이지 초기화.
            /// </summary>
            protected override void InitPage()
            {
                // Page Setting & Validation
                this.MenuIdx = 6;
                if (ValidPageSetting() == false) return;

                // To do
                GetList(1);
            }

            /// <summary>
            /// 검색버튼 클릭.
            /// </summary>
            protected void btnSearch_Click(object sender, EventArgs e)
            {
                try
                {
                    GetList(1);
                }
                catch (Exception ex)
                {
                    HandleError(ex);
                }
            }

            /// <summary>
            /// Page Action (Paging, Sorting).
            /// </summary>
            protected void PageAction(object sender, EventArgs e)
            {
                try
                {
                    //GetList(Convert.ToInt32(hfPage.Value));
                }
                catch (Exception ex)
                {
                    HandleError(ex);
                }
            }

            /// <summary>
            /// 목록 검색.
            /// </summary>
            private void GetList(int nPage)
            {
                string sSql;

                //----- 검색조건 생성
                string sWhere = string.Empty;
                /*
                if (tbKeyword.Text.Trim() != string.Empty)
                    sWhere = "AND " + ddlField.SelectedValue + " LIKE '%" + tbKeyword.Text.Trim() + "%' ";
                */
                //----- 전체레코드 조회
                int iTotalRecord;
                if (nPage == 1)
                {
                    sSql = string.Format(SelCount, sWhere);
                    iTotalRecord = this.cDBLadyTeller.GetSingleInt(sSql);
                    hfTotalRecord.Value = iTotalRecord.ToString();
                }
                else
                {
                    iTotalRecord = Convert.ToInt32(hfTotalRecord.Value);
                }
                lblCount.Text = iTotalRecord.ToString("N0");
                
                //----- 페이지목록 조회
                if (iTotalRecord == 0)
                {
                    rptList.DataSource = null;
                    rptList.DataBind();
                    lblPaging.Text = string.Empty;
                }
                else
                {
                    sSql = string.Format(SelListPage, Constants.ListViewCount, nPage, sWhere);
                    rptList.DataSource = this.cDBUtil.GetDataTable(sSql);
                    rptList.DataBind();
                    lblPaging.Text = Paging.GetPaging(Constants.ListViewCount, iTotalRecord, nPage);
                }
            }

            #region " Query "

            /// <summary>
            /// SELECT - 카운트.
            /// </summary>
            private const string SelCount = @"
SELECT      COUNT(*) 
FROM        T_BoardEvent 
WHERE       DelDT IS NULL {0}
";

            /// <summary>
            /// SELECT - 리스트 페이징.
            /// </summary>
            public const string SelListPage = @"
SELECT		*
FROM
(SELECT     * 
			, ROW_NUMBER() OVER (ORDER BY Idx DESC) AS RowNo
FROM        T_BoardEvent 
WHERE       DelDT IS NULL {2}) AS M
WHERE		RowNo BETWEEN ({0}*({1}-1))+1 AND {0}*{1}
";

            #endregion


      
       
    }
}